﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="YoProgramo.Domain.BusinessLogic.Service"%>
<%@ Import Namespace="YoProgramo.Domain.BusinessLogic.Extensions"%>
<%@ Import Namespace="YoProgramo.Domain.Core.Interfaces"%>
<%@ Import Namespace="Microsoft.Practices.ServiceLocation"%>
<%  
    IUser user = null;
    if(HttpContext.Current.User.Identity.IsAuthenticated)
    {
      IUserRepository _userrepository = ServiceLocator.Current.GetInstance<IUserRepository>();
      user = ((IUser)_userrepository.FindByUserName(Page.User.Identity.Name));
      if (user == null) {
        var FormsAuth = new FormsAuthenticationService();
        FormsAuth.SignOut();
      }        
    }

    if (user != null) {        
%>
        Hola <%= Html.RouteLink(Page.User.Identity.Name, "Default", new { action = "ViewProfile", controller = "User", id = user.Id })%>! <%if (user.IsInRole(YoProgramo.Domain.Core.Roles.Administrator)){ %> - <%= Html.RouteLink("Adm", "Admin", new { action = "Index", controller = "Admin"})%> <% }%> - <%= Html.RouteLink("Mis Preguntas", "Default", new { action = "StoryList", controller = "User", id = user.Id })%> - <%= Html.RouteLink("Mis Favoritas", "Default", new { action = "FavoriteList", controller = "User", id = user.Id })%>
        [ <%= Html.RouteLink("Salir", "Default", new { controller = "Account", action = "LogOff" })%> ]
<%
    }
    else {
%> 
        [ <%= Html.RouteLink("Entrar", "Default", new { controller = "Account", action = "LogOn" })%> ] - [ <%= Html.RouteLink("Registrarse", "Default", new { controller = "Account", action = "Register" })%> ]
<%
    }
%>
